package com.cms.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.cms.entity.base.BaseTag;
import com.cms.utils.WebUtils;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * Entity - 标签
 *
 *
 *
 */
@SuppressWarnings("serial")
@EqualsAndHashCode(callSuper = false)
@TableName("cms_tag")
public class Tag extends BaseTag {


	/**
	 * 获取路径
	 *
	 * @return 路径
	 */
	public String getPath() {
		String contextPath = WebUtils.getContextPath();
		String url="";
		String param = "";
		Map<String,Object> map = SqlRunner.db().selectOne("select * from cms_site where id={0}",getSiteId());
		Site site = JSON.parseObject(JSON.toJSONString(map), Site.class);
		String siteCat = site.getCat();
		if(StringUtils.isNotBlank(siteCat)){
			url+=contextPath+"/"+siteCat;
		}
		String cat = getCat();
		if(StringUtils.isNotBlank(cat)){
			url+=contextPath+"/tag/"+cat;
		}else{
			url+=contextPath+"/tag";
			param+="&id="+getId();
		}
		if(StringUtils.isNotBlank(param)){
			param = "?" +param.substring(1);
		}
		return url+param;
	}

}
